#ifndef _LIBCCMD_CMD_H_
#define _LIBCCMD_CMD_H_

#include <stdint.h>
#include <getopt.h>

// 默认最大选项数目
#define DEFAULT_OPTION_NUM (64)

/**
 * @brief Log levels used to determine if message of certain severity should be printed.
 */
typedef enum 
{
    CCMD_LL_NONE = 0,  /**< Do not print any messages. */
    CCMD_LL_ERR,       /**< Print only error messages. */
    CCMD_LL_WRN,       /**< Print error and warning messages. */
    CCMD_LL_INF,       /**< Besides errors and warnings, print some other informational messages. */
    CCMD_LL_DBG,        /**< Print all messages including some development debug messages. */
} ccmd_log_level_t;

typedef int (*cmd_opt_parser)(void *opt_results, char *option, char *arg);
typedef void (*cmd_opt_help_printer)(const char *option);
typedef void (*cmd_log_printer)(uint32_t level, const char *msg);

/* 命令选项信息及回调函数 */
typedef struct {
    const char *name;
    const char *help;
    cmd_opt_help_printer help_fn;
    cmd_opt_parser parser_fn;
} cmd_opt_cfg;

/**
*@ Description: 设置ccmd的调试信息输出函数
*@ cb: [in] 调试信息输出函数
*@ return void
*/
void set_cmd_log_printer(cmd_log_printer cb);

/**
*@ Description: 解析命令行参数
*@ options: [in, out] 选项解析结果
*@ argc: [in] 选项个数
*@ argv: 选项数组
*@ return void
*/
int cmd_parse(void *results, const int argc, const char **argv);


/**
*@ Description: 增加一个选项配置，必须在调用cmd_parse之前注册才生效
*@ cfg: [in] 选项配置
*@ opt: [in] 选项关联的opt配置
*@ return 0：成功 非0：失败
*/
int add_cmd_opt(cmd_opt_cfg *cfg, struct option *opt_cfg);


/**
*@ Description: 根据选项配置，显示帮助信息到stdout
*@ return void
*/
void usage(void);



#endif
